import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { WinstonModule } from './winston/winston.module';
import { format, transports } from 'winston';
import * as chalk from 'chalk';
import { ConfigModule } from '@nestjs/config';
import config from './config';

@Module({
    // 抽离出 WinstonModule 才需要写 不抽离动态模块 imports 为空数组
    imports: [
        WinstonModule.forRoot({
            level: 'debug',
            transports: [
                new transports.Console({
                    format: format.combine(
                        format.colorize(),
                        format.printf(({ context, level, message, time }) => {
                            const appStr = chalk.green(`[NEST]`);
                            const contextStr = chalk.yellow(`[${context}]`);
                            return `${appStr} ${time} - ${level} ${contextStr} ${message} `;
                        }),
                    ),
                }),
            ],
        }),
        // ConfigModule.forRoot() // 加载 config 配置  无config文件时
        ConfigModule.forRoot({
            isGlobal:true , // 设置config时是全局模块
            load:[config]
        })
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule { }
